Telegram Group & Telegram Channel
🧠 Задача на Go (1.22+)


package main

import "fmt"

func main() {
m = map[string]int{"a": 1, "b": 2, "c": 3}

defer fmt.Println("done")

for k, v := range m {
defer fmt.Println(k, v)
}
}


Что выведет этот код?

A.
c 3
b 2
a 1
done

B.
done
a 1
b 2
c 3

C.
done
c 3
b 2
a 1

D.
a 3
a 3
a 3
done

Почему A? — в Go 1.22 range-переменные k и v создаются на каждом шаге заново, а defer захватывает копии, не ссылки.



tg-me.com/golangtests/770
Create:
Last Update:

🧠 Задача на Go (1.22+)


package main

import "fmt"

func main() {
m = map[string]int{"a": 1, "b": 2, "c": 3}

defer fmt.Println("done")

for k, v := range m {
defer fmt.Println(k, v)
}
}


Что выведет этот код?

A.
c 3
b 2
a 1
done

B.
done
a 1
b 2
c 3

C.
done
c 3
b 2
a 1

D.
a 3
a 3
a 3
done

Почему A? — в Go 1.22 range-переменные k и v создаются на каждом шаге заново, а defer захватывает копии, не ссылки.

BY Go tests


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/golangtests/770

View MORE
Open in Telegram


Go tests Telegram | DID YOU KNOW?

Date: |

Telegram announces Search Filters

With the help of the Search Filters option, users can now filter search results by type. They can do that by using the new tabs: Media, Links, Files and others. Searches can be done based on the particular time period like by typing in the date or even “Yesterday”. If users type in the name of a person, group, channel or bot, an extra filter will be applied to the searches.

Tata Power whose core business is to generate, transmit and distribute electricity has made no money to investors in the last one decade. That is a big blunder considering it is one of the largest power generation companies in the country. One of the reasons is the company's huge debt levels which stood at ₹43,559 crore at the end of March 2021 compared to the company’s market capitalisation of ₹44,447 crore.

Go tests from cn


Telegram Go tests
FROM USA